package com.wyp168.leetcode.dayQuestion;

import java.util.Objects;

/**
 * @ClassName AreAlmostEqualSolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/11 08:40
 */
public class AreAlmostEqualSolution {
    public static void main(String[] args) {
        AreAlmostEqualSolution solution = new AreAlmostEqualSolution();
        String s1 = "abcd";
        String s2 = "dcba";
        System.out.println(solution.areAlmostEqual(s1, s2));
    }

    public boolean areAlmostEqual (String s1, String s2) {
        //默认s1.length() == s2.length()
        int length = s1.length();
        int s1Index = 0;
        int s2Index = 0;

        char[] diffChars = new char[4]; //0 - 3

        int index = 0;

        while (s1Index < length) {
            if (s1.charAt(s1Index) == s2.charAt(s2Index)) {
                s1Index ++;
                s2Index ++;
                continue;
            }

            if (index < diffChars.length - 1) {
                diffChars[index ++] = s1.charAt(s1Index ++);
                diffChars[index ++] = s2.charAt(s2Index ++);
            } else {
                return false;
            }
        }

        if (index == 0 || diffChars[0] == diffChars[3] && diffChars[1] == diffChars[2]) {
            return true;
        } else {
            return false;
        }

    }
}
